package com.travelmood.service;

import com.travelmood.pojo.Place;
import com.travelmood.mapper.PlaceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import java.util.List;

@Slf4j//调试用的

@Service
public class PlaceService {

    @Autowired
    private PlaceMapper placeMapper;

    public void addPlace(Place place, Integer userId) {
        place.setUserId(userId);
        placeMapper.insertPlace(place);
    }

    public List<Place> getPlacesByUserId(Integer userId) {
        log.info("开始查询用户 ID 为 {} 的所有地点", userId);
        List<Place> places = placeMapper.selectPlacesByUserId(userId);
        log.info("查询到的地点: {}", places);
        return places;
    }

    public Place findPlaceById(Integer placeId) {
        return placeMapper.selectPlaceById(placeId);
    }

    public void updatePlace(Place place, Integer userId) {
        place.setUserId(userId);
        placeMapper.updatePlace(place);
    }

    public void deletePlaceById(Integer placeId, Integer userId) {
        placeMapper.deletePlaceById(placeId, userId);
    }
}
